Skip to content

Conversation

@gimlichael
Copy link
Member

@gimlichael gimlichael commented Apr 7, 2025

This pull request includes several changes to the Codebelt.Extensions.Xunit.Hosting.AspNetCore package, primarily focusing on renaming interfaces and classes, adding new extensions and fixtures, and updating package versions.

Here are the most important changes:

Interface and Class Renaming:

  • Renamed IAspNetCoreHostFixture to IWebHostFixture and updated its implementation to align with the new naming convention.
  • Renamed IWebHostTest to inherit from IHostTest instead of IGenericHostTest.

New Extensions and Fixtures:

  • Added BlockingWebHostFixture class to provide a synchronous implementation of the IWebHostFixture interface.
  • Added HostBuilderApplicationExtensions class to provide extension methods for IHostApplicationBuilder.
  • Added MinimalWebHostFixture class as a minimal style implementation of WebHostFixture.
  • Added MinimalWebHostFixtureExtensions class to provide extension methods for IMinimalWebHostFixture.

Code Removal:

  • Removed AspNetCoreHostFixtureExtensions class and its methods.
  • Removed BlockingAspNetCoreHostFixture class.

Package Version Update:

  • Updated System.Threading.Tasks.Extensions package version from 4.6.2 to 4.6.3 in Directory.Packages.props.

Minor Changes:

  • Updated remarks in HttpClientExtensions to reflect the new IWebHostFixture interface.

These changes improve the structure and functionality of the Codebelt.Extensions.Xunit.Hosting.AspNetCore package, making it more consistent and easier to use.

Summary by CodeRabbit

  • New Features

    • Introduced a streamlined minimal hosting model with new APIs and factory methods for easier, synchronous integration testing of web applications.
    • Added new classes and interfaces such as HostTest, IGenericHostFixture, GenericHostFixture, MinimalHostFixture, and MinimalHostTestFactory to enhance testing capabilities.
  • Refactor

    • Renamed and reorganized hosting interfaces and classes to align with modern minimal hosting patterns, enhancing clarity, consistency, and error handling.
    • Updated various interfaces and classes to reflect changes in hosting structure, including renaming AspNetCoreHostFixture to WebHostFixture and IAspNetCoreHostFixture to IWebHostFixture.
  • Chores

    • Updated an underlying dependency to a newer version, ensuring improved stability and performance while removing obsolete testing utilities.

@gimlichael gimlichael self-assigned this Apr 7, 2025
Copilot AI review requested due to automatic review settings April 7, 2025 16:28
@coderabbitai
Copy link

coderabbitai bot commented Apr 7, 2025

Walkthrough

This commit includes modifications across hosting and test framework files. It updates the package version for System.Threading.Tasks.Extensions and refactors the hosting infrastructure by renaming ASP.NET Core fixtures to Web fixtures, removing obsolete types, and introducing a minimal hosting model. New classes, interfaces, extension methods, and factory methods streamline host configuration and testing, while adjustments to test files ensure consistency with the new structures. The changes also simplify exception handling, service resolution, and logging integration across the suite.

Changes

File(s) Change Summary
Directory.Packages.props Updated System.Threading.Tasks.Extensions version from 4.6.2 to 4.6.3.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixtureExtensions.cs
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingAspNetCoreHostFixture.cs
src/Codebelt.Extensions.Xunit.Hosting/HostFixtureExtensions.cs
src/Codebelt.Extensions.Xunit.Hosting/IServiceTest.cs
Removed obsolete extension methods and classes related to legacy ASP.NET Core host fixtures.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/*.cs (e.g., Files renamed: IAspNetCoreHostFixture → IWebHostFixture, introduction of BlockingWebHostFixture, HostBuilderApplicationExtensions, updated XML docs) Renamed and refactored ASP.NET Core-specific fixtures and interfaces; updated documentation and inheritance hierarchies.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/*.cs and MinimalWebHostFixture.cs Introduced new classes and interfaces (e.g., IMinimalWebHostFixture, MinimalWebHostFixture, MinimalWebHostTest, MinimalWebHostTestFactory) to support a minimal hosting model with streamlined configuration and hosting behavior.
src/Codebelt.Extensions.Xunit.Hosting/*.cs (e.g., GenericHostFixture.cs, GenericHostFixtureExtensions.cs, HostTest.cs, HostTestFactory.cs, IHostFixture.cs, IHostTest.cs, etc.) Refactored the generic host fixture and test infrastructure by removing deprecated methods, simplifying configuration callbacks, and updating inheritance and interface contracts.
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/* and test/Codebelt.Extensions.Xunit.Hosting.Tests/* Updated test classes to reflect fixture renames, updated generic constraints, adjusted service resolution (using Host.Services), and streamlined logging integration and exception handling.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test/Factory
    participant MHF as MinimalHostFixture
    participant HBA as HostBuilderApplication
    participant Host as IHost
    T->>MHF: Invoke Create/ConfigureHost()
    MHF->>HBA: Initialize host configuration
    HBA-->>MHF: Return configured Application Builder
    MHF->>Host: Build and run host
    Host-->>T: Return running host instance
Loading

Possibly related PRs

  • V9.0.0/rtm #21: Updates package versions in Directory.Packages.props, including System.Threading.Tasks.Extensions, aligning with dependency version management.

Poem

I’m a rabbit hopping through lines of code,
Leaping from fixtures old to a new minimal mode.
I nibble on tests, with logic so refined,
And burrow through changes with a clear, steady mind.
With each new class and method so neat,
I celebrate the refactor with a happy heartbeat!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between bbbb2dd and c95fb3c.

📒 Files selected for processing (62)
  • .nuget/Codebelt.Extensions.Xunit.App/PackageReleaseNotes.txt (1 hunks)
  • .nuget/Codebelt.Extensions.Xunit.Hosting.AspNetCore/PackageReleaseNotes.txt (1 hunks)
  • .nuget/Codebelt.Extensions.Xunit.Hosting/PackageReleaseNotes.txt (2 hunks)
  • .nuget/Codebelt.Extensions.Xunit/PackageReleaseNotes.txt (1 hunks)
  • CHANGELOG.md (1 hunks)
  • Directory.Packages.props (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixtureExtensions.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingAspNetCoreHostFixture.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingWebHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HostBuilderApplicationExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HttpClientExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IMinimalWebHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IWebHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IWebHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/MinimalWebHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixtureExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTestFactory.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixture.cs (3 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixtureExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (2 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (5 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/GenericHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/GenericHostFixtureExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/GenericHostTestFactory.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (3 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/HostFixtureExtensions.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (3 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/HostTestFactory.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IEnvironmentTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IGenericHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IGenericHostTest.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IMinimalHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IServiceTest.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/Internal/HostTest.cs (3 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/Internal/MinimalHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixtureExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTestFactory.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/InvalidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/ValidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalMvcWebHostTestTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestFactoryTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MvcWebHostTestTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostFixtureTest.cs (4 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs (5 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestTest.cs (3 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/InvalidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/MinimalValidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/ValidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/GenericHostFixtureTest.cs (3 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestFactoryTest.cs (4 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestTest.cs (3 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostFixtureTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestFactoryTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestTest.cs (1 hunks)
💤 Files with no reviewable changes (6)
  • src/Codebelt.Extensions.Xunit.Hosting/HostFixtureExtensions.cs
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingAspNetCoreHostFixture.cs
  • src/Codebelt.Extensions.Xunit.Hosting/IGenericHostTest.cs
  • src/Codebelt.Extensions.Xunit.Hosting/GenericHostTestFactory.cs
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixtureExtensions.cs
  • src/Codebelt.Extensions.Xunit.Hosting/IServiceTest.cs

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 56 out of 57 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • Directory.Packages.props: Language not supported
Comments suppressed due to low confidence (2)

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixture.cs:70

  • Since the PR renames the property from 'HostingEnvironment' to 'Environment' in other parts of the code (e.g. when configuring the host), please ensure this change is applied consistently across all files to prevent potential confusion.
Environment = context.HostingEnvironment;

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HttpClientExtensions.cs:21

  • Confirm that all XML documentation references have been updated to reflect the new naming convention ('IWebHostFixture') consistently throughout the code.
/// <remarks>Designed to be used in conjunction with <see cref="WebHostTestFactory.RunAsync(System.Action{Microsoft.Extensions.DependencyInjection.IServiceCollection},System.Action{Microsoft.AspNetCore.Builder.IApplicationBuilder},System.Action{Microsoft.Extensions.Hosting.IHostBuilder},System.Func{System.Net.Http.HttpClient,System.Threading.Tasks.Task{System.Net.Http.HttpResponseMessage}},IWebHostFixture)"/> and <see cref="WebHostTestFactory.RunWithHostBuilderContextAsync(System.Action{Microsoft.Extensions.Hosting.HostBuilderContext,Microsoft.Extensions.DependencyInjection.IServiceCollection},System.Action{Microsoft.Extensions.Hosting.HostBuilderContext,Microsoft.AspNetCore.Builder.IApplicationBuilder},System.Action{Microsoft.Extensions.Hosting.IHostBuilder},System.Func{System.Net.Http.HttpClient,System.Threading.Tasks.Task{System.Net.Http.HttpResponseMessage}},IWebHostFixture)"/>.</remarks>

@codecov
Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 96.96970% with 10 lines in your changes missing coverage. Please review.

Project coverage is 93.89%. Comparing base (bbbb2dd) to head (cdd4d42).

Files with missing lines Patch % Lines
....Hosting.AspNetCore/Internal/MinimalWebHostTest.cs 95.74% 0 Missing and 2 partials ⚠️
...s.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs 96.00% 0 Missing and 2 partials ⚠️
...belt.Extensions.Xunit.Hosting/Internal/HostTest.cs 50.00% 0 Missing and 2 partials ⚠️
...tensions.Xunit.Hosting/Internal/MinimalHostTest.cs 93.93% 0 Missing and 2 partials ⚠️
...ing.AspNetCore/HostBuilderApplicationExtensions.cs 75.00% 1 Missing ⚠️
...c/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #30      +/-   ##
==========================================
+ Coverage   91.17%   93.89%   +2.71%     
==========================================
  Files          32       44      +12     
  Lines         714      884     +170     
  Branches       91      121      +30     
==========================================
+ Hits          651      830     +179     
+ Misses         58       44      -14     
- Partials        5       10       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (25)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/MinimalWebHostTest.cs (1)

47-56: Add clarifying documentation for Tweaker.Adjust.

The usage of Tweaker.Adjust for bridging the HostBuilderContext is not immediately obvious. Adding a brief comment or docstring explaining why this step is needed can improve maintainability and clarity.

src/Codebelt.Extensions.Xunit.Hosting/Internal/MinimalHostTest.cs (2)

14-19: Review disposal strategy for the created Host.

If the host is not disposed, resources may persist beyond test execution, leading to potential memory or resource leaks in long test runs. Consider implementing a teardown or disposal pattern (e.g., IAsyncLifetime).


40-51: Document reasons for using the adjusted HostBuilderContext.

As in the ASP.NET Core version, clarify the motivation for the transformation via Tweaker.Adjust. This step may confuse new contributors without proper comments or docstrings.

src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTestFactory.cs (1)

15-16: Fix XML documentation to match actual parameter types.

The parameter doc comments refer to IHostBuilder instead of IHostApplicationBuilder. Align them to avoid misleading readers or automated documentation tools.

-/// <param name="hostSetup">The <see cref="IHostBuilder"/> which may be configured.</param>
+/// <param name="hostSetup">The <see cref="IHostApplicationBuilder"/> which may be configured.</param>

Also applies to: 26-28

test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestFactoryTest.cs (1)

13-25: Good implementation, consider improving variable naming

The test correctly verifies that the caller type's declaring type matches the current test class and that the application name equals the assembly name. However, the variable names sut1 and sut2 could be more descriptive for better readability.

-    Type sut1 = GetType();
-    string sut2 = null;
+    Type callerType = GetType();
+    string applicationName = null;
     var middleware = MinimalHostTestFactory.Create(Assert.NotNull, host =>
     {
-        sut2 = host.Environment.ApplicationName;
+        applicationName = host.Environment.ApplicationName;
     });

-    Assert.True(sut1 == middleware.CallerType.DeclaringType);
-    Assert.Equal(GetType().Assembly.GetName().Name, sut2);
+    Assert.True(callerType == middleware.CallerType.DeclaringType);
+    Assert.Equal(GetType().Assembly.GetName().Name, applicationName);
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalMvcWebHostTestTest.cs (1)

35-42: Duplicate test method

This test is identical to the previous one. Consider either removing the duplicate or modifying it to test a different aspect of the controller.

test/Codebelt.Extensions.Xunit.Hosting.Tests/GenericHostFixtureTest.cs (1)

27-27: Potential duplication in inline fixture creation.
Creating a fresh GenericHostFixture inline here replicates the _hostFixture instance already in use. If this test doesn't need a unique fixture, consider reusing the existing one to reduce overhead.

- var invalidHostTest = new InvalidHostTest<GenericHostFixture>(new GenericHostFixture());
+ var invalidHostTest = new InvalidHostTest<GenericHostFixture>(_hostFixture);
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs (1)

8-8: Class naming could cause confusion.
WebHostTest inherits from WebHostTest<IWebHostFixture> (a generic base). While valid, it might be unclear when reading code references which type is in use. Consider a more descriptive name to avoid overshadowing the generic base class.

src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTest.cs (2)

28-30: Clarify the purpose of the empty ConfigureHost method.
This virtual method is currently empty, which is fine if it’s meant purely for optional overrides. However, it would help maintainers to include a brief inline comment or XML documentation remark clarifying that this is a placeholder or extension point.


43-45: Fix misleading XML documentation reference to HostTest{T}.
The summary for your constructor says it initializes a new instance of <see cref="HostTest{T}" />, but the actual class name is MinimalHostTest<T>. Update the XML docs to prevent confusion.

-/// Initializes a new instance of the <see cref="HostTest{T}" /> class.
+/// Initializes a new instance of the <see cref="MinimalHostTest{T}" /> class.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixture.cs (2)

39-43: Consider allowing configurable environment names.
Hardcoding "Development" is often useful for local testing. However, if other scenarios (e.g., staging, production-like tests) need coverage, a parameter or property for the environment name could be more flexible.

 var hb = WebApplication.CreateBuilder(new WebApplicationOptions()
 {
-    EnvironmentName = "Development",
+    EnvironmentName = EnvironmentName ?? "Development",
     ApplicationName = hostTest.CallerType.Assembly.GetName().Name
 });

56-59: Ensure proper disposal of the built application.
Leaving the application running or undisposed can create resource leaks (ports, background threads, etc.). Consider disposing of webApplication or calling Host.Dispose() at an appropriate lifecycle point (e.g., post-test teardown), unless handled elsewhere.

src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (1)

16-22: Consider asynchronous start to prevent potential deadlocks
The _hostRunnerCallback uses a blocking call to host.StartAsync(). While referencing the linked workaround, consider an await-based approach to reduce potential deadlocks.

-            Task.Run(() => host.StartAsync().ConfigureAwait(false))
-                .ConfigureAwait(false)
-                .GetAwaiter()
-                .GetResult();
+            await host.StartAsync().ConfigureAwait(false);
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (4)

11-11: Fix grammatical construction in the doc comment.

Currently, the sentence in the <summary> is somewhat unclear.

Here's a proposed diff to improve readability:

-/// Represents the non-generic base class from its generic equivalent should derive.
+/// Represents the non-generic base class from which its generic equivalent should derive.

27-36: Consider adding null checks for configuration and environment.

While these are likely ensured by the fixture, it’s safer to guard against potential null references.

For example:

 public virtual void Configure(IConfiguration configuration, IHostEnvironment environment)
 {
+    if (configuration == null) throw new ArgumentNullException(nameof(configuration));
+    if (environment == null) throw new ArgumentNullException(nameof(environment));

     Configuration = configuration;
     Environment = environment;
 }

58-66: Documentation references an unusually complex design.

The remark states the design is "rather complex," but it does not explain the specific constraints. Consider clarifying why xUnit's shared context requirement leads to this pattern.


84-84: Clarify parameter documentation for skip host fixture initialization.

The doc comment simply states that it "indicates whether to skip the host fixture initialization," but readers may benefit from insight on when or why they'd skip it, e.g. advanced customization or environment setup.

test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestTest.cs (4)

23-29: Consider verifying host creation exceptions.

In the constructor, a new service scope and _correlationsFactory are set up. If hostFixture.Host or Services fail to initialize, you may encounter runtime errors. An additional test to confirm a valid Host object (and no exceptions thrown) could bolster reliability.


31-38: Tests appear correct but rely on repeated "ScopedCorrelation" additions.

Each test adds a ScopedCorrelation to ScopedCorrelations. Evaluate whether these repeated additions are strictly necessary or if a shared test setup would suffice. Reducing repeated code can clarify the scope-lifetime assertions.


58-62: Ensure transient timing is not a factor in host startup.

Assert.True(_isHostRunning); is straightforward. If host startup is slow, the ApplicationStarted callback might not register quickly. In typical scenarios this is fine, but consider defensive checks if test environments vary significantly.


76-86: Add further checks for logging, disposal, or concurrency.

The Test_VerifyAbstractions() method checks the basic interface implementations. A complementary test verifying correct disposal or concurrency behavior (e.g., logging scopes across test runs) could add further confidence, especially in parallel test runs.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTestFactory.cs (2)

18-29: Initialize or validate the fixture consistently.

Within Create(...), a new MinimalWebHostFixture is spawned by default, but if the passed hostFixture has partial state, it might lead to inconsistent initialization downstream. Consider either fully re-initializing or throwing an exception if the fixture isn’t in a valid state.


59-72: Extend or overload the method to handle advanced request scenarios.

RunWithHostBuilderContextAsync is helpful. If more advanced test scenarios (like configuring environment variables or multiple pipelines) are common, consider providing an overloaded method that allows for additional bundling or chaining of configurations.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (1)

50-60: Property documentation is succinct and consistent.
Consider adding a short note clarifying that Application is valid only after the fixture has been initialized, to guide new contributors.

 /// <summary>
 /// Gets the <see cref="IApplicationBuilder"/> initialized by the <see cref="IHost"/>.
 /// </summary>
 /// <value>The <see cref="IApplicationBuilder"/> initialized by the <see cref="IHost"/>.</value>
+/// <remarks>Ensure that the host fixture is initialized before accessing <see cref="Application"/>.</remarks>
 public IApplicationBuilder Application { get; protected set; }
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixtureExtensions.cs (1)

13-16: Verify XML documentation accuracy regarding interface references.

The documentation remarks on line 15 reference IHostFixture.ConfigureCallback and IHostFixture.Host, but the method extends IMinimalHostFixture. While this might be correct if IMinimalHostFixture inherits from IHostFixture, it would be clearer to reference the immediate interface when possible.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbbb2dd and cdd4d42.

📒 Files selected for processing (57)
  • Directory.Packages.props (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixtureExtensions.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingAspNetCoreHostFixture.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingWebHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HostBuilderApplicationExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HttpClientExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IMinimalWebHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IWebHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IWebHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/MinimalWebHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixtureExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTestFactory.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixture.cs (3 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixtureExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (2 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (5 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/GenericHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/GenericHostFixtureExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/GenericHostTestFactory.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (3 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/HostFixtureExtensions.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (3 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/HostTestFactory.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IEnvironmentTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IGenericHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IGenericHostTest.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IMinimalHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/IServiceTest.cs (0 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/Internal/HostTest.cs (3 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/Internal/MinimalHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixture.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixtureExtensions.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTest.cs (1 hunks)
  • src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTestFactory.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/InvalidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/ValidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalMvcWebHostTestTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestFactoryTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MvcWebHostTestTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostFixtureTest.cs (4 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs (5 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestTest.cs (3 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/InvalidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/MinimalValidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/ValidHostTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/GenericHostFixtureTest.cs (3 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestFactoryTest.cs (4 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestTest.cs (3 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostFixtureTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestFactoryTest.cs (1 hunks)
  • test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestTest.cs (1 hunks)
💤 Files with no reviewable changes (6)
  • src/Codebelt.Extensions.Xunit.Hosting/IServiceTest.cs
  • src/Codebelt.Extensions.Xunit.Hosting/HostFixtureExtensions.cs
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingAspNetCoreHostFixture.cs
  • src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixtureExtensions.cs
  • src/Codebelt.Extensions.Xunit.Hosting/GenericHostTestFactory.cs
  • src/Codebelt.Extensions.Xunit.Hosting/IGenericHostTest.cs
🧰 Additional context used
🧬 Code Definitions (29)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingWebHostFixture.cs (1)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixture.cs (2)
  • WebHostFixture (18-108)
  • WebHostFixture (23-25)
test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/InvalidHostTest.cs (2)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/InvalidHostTest.cs (2)
  • InvalidHostTest (5-10)
  • InvalidHostTest (7-9)
src/Codebelt.Extensions.Xunit/Test.cs (2)
  • Test (14-157)
  • Test (52-56)
src/Codebelt.Extensions.Xunit.Hosting/Internal/MinimalHostTest.cs (5)
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTest.cs (6)
  • MinimalHostTest (12-31)
  • MinimalHostTest (19-21)
  • MinimalHostTest (40-78)
  • MinimalHostTest (51-53)
  • MinimalHostTest (65-77)
  • ConfigureHost (28-30)
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixtureExtensions.cs (1)
  • HasValidState (17-22)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (1)
  • Configure (32-36)
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixture.cs (1)
  • ConfigureHost (32-53)
src/Codebelt.Extensions.Xunit.Hosting/IMinimalHostFixture.cs (1)
  • ConfigureHost (25-25)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/InvalidHostTest.cs (2)
test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/InvalidHostTest.cs (2)
  • InvalidHostTest (5-10)
  • InvalidHostTest (7-9)
src/Codebelt.Extensions.Xunit/Test.cs (2)
  • Test (14-157)
  • Test (52-56)
src/Codebelt.Extensions.Xunit.Hosting/IGenericHostFixture.cs (2)
src/Codebelt.Extensions.Xunit.Hosting/GenericHostFixture.cs (1)
  • ConfigureHost (35-79)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (1)
  • ConfigureHost (109-111)
test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/ValidHostTest.cs (1)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (5)
  • HostTest (16-55)
  • HostTest (23-25)
  • HostTest (65-118)
  • HostTest (76-78)
  • HostTest (90-103)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/MinimalWebHostTest.cs (4)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTest.cs (4)
  • MinimalWebHostTest (17-66)
  • MinimalWebHostTest (25-27)
  • MinimalWebHostTest (39-53)
  • ConfigureApplication (65-65)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixtureExtensions.cs (1)
  • HasValidState (18-22)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixture.cs (1)
  • ConfigureHost (34-62)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (1)
  • Configure (32-36)
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTestFactory.cs (2)
src/Codebelt.Extensions.Xunit.Hosting/Internal/MinimalHostTest.cs (3)
  • MinimalHostTest (7-52)
  • MinimalHostTest (14-19)
  • MinimalHostTest (21-26)
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixture.cs (2)
  • MinimalHostFixture (12-60)
  • MinimalHostFixture (17-19)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IWebHostTest.cs (1)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (2)
  • IWebHostTest (26-29)
  • IWebHostTest (39-42)
src/Codebelt.Extensions.Xunit.Hosting/HostTestFactory.cs (1)
src/Codebelt.Extensions.Xunit.Hosting/Internal/HostTest.cs (3)
  • HostTest (7-57)
  • HostTest (14-19)
  • HostTest (21-26)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixture.cs (3)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs (4)
  • ConfigureHost (59-63)
  • WebHostTest (8-76)
  • WebHostTest (17-23)
  • WebHostTest (25-31)
src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (1)
  • HasTypes (37-50)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (3)
  • WebHostTest (14-61)
  • WebHostTest (22-24)
  • WebHostTest (33-48)
test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestFactoryTest.cs (1)
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTestFactory.cs (1)
  • MinimalHostTestFactory (10-35)
test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestTest.cs (2)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (5)
  • HostTest (16-55)
  • HostTest (23-25)
  • HostTest (65-118)
  • HostTest (76-78)
  • HostTest (90-103)
src/Codebelt.Extensions.Xunit.Hosting/HostTestFactory.cs (1)
  • HostTestFactory (10-35)
test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestFactoryTest.cs (1)
src/Codebelt.Extensions.Xunit.Hosting/HostTestFactory.cs (1)
  • HostTestFactory (10-35)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestFactoryTest.cs (4)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostFixtureTest.cs (4)
  • Fact (15-23)
  • Fact (25-34)
  • Fact (36-48)
  • Fact (50-63)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs (3)
  • Fact (26-51)
  • Fact (53-81)
  • Fact (83-98)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTestFactory.cs (1)
  • MinimalWebHostTestFactory (16-73)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Http/Features/FakeHttpResponseFeature.cs (1)
  • OnStarting (30-35)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestTest.cs (4)
src/Codebelt.Extensions.Xunit.Hosting/XunitTestLoggerProvider.cs (1)
  • ILogger (25-30)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostFixtureTest.cs (4)
  • Fact (15-23)
  • Fact (25-34)
  • Fact (36-48)
  • Fact (50-63)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (1)
  • WebHostTestFactory (16-73)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestTest.cs (1)
  • ConfigureApplication (160-164)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs (4)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (4)
  • WebHostTest (14-61)
  • WebHostTest (22-24)
  • WebHostTest (33-48)
  • ConfigureApplication (60-60)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixtureExtensions.cs (1)
  • HasValidState (18-22)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixture.cs (1)
  • ConfigureHost (38-95)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (1)
  • Configure (32-36)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalMvcWebHostTestTest.cs (3)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MvcWebHostTestTest.cs (3)
  • Fact (25-32)
  • Fact (34-41)
  • ConfigureApplication (52-56)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestTest.cs (2)
  • ConfigureHost (143-158)
  • ConfigureApplication (160-164)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/FakeController.cs (1)
  • FakeController (9-11)
src/Codebelt.Extensions.Xunit.Hosting/IMinimalHostFixture.cs (3)
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixture.cs (1)
  • ConfigureHost (32-53)
src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTest.cs (1)
  • ConfigureHost (28-30)
src/Codebelt.Extensions.Xunit.Hosting/Internal/MinimalHostTest.cs (1)
  • ConfigureHost (40-51)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestTest.cs (6)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/ServiceCollectionExtensions.cs (1)
  • IHttpContextAccessor (40-43)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/BoolOptions.cs (1)
  • BoolOptions (5-18)
src/Codebelt.Extensions.Xunit.Hosting/XunitTestLoggerProvider.cs (1)
  • ILogger (25-30)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (1)
  • WebHostTestFactory (16-73)
test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestTest.cs (1)
  • ConfigureHost (93-98)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/ValidHostTest.cs (1)
  • ConfigureApplication (17-20)
src/Codebelt.Extensions.Xunit.Hosting/GenericHostFixture.cs (3)
src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (3)
  • HostFixture (13-187)
  • HostFixture (27-29)
  • HasTypes (37-50)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (6)
  • ConfigureHost (109-111)
  • HostTest (16-55)
  • HostTest (23-25)
  • HostTest (65-118)
  • HostTest (76-78)
  • HostTest (90-103)
src/Codebelt.Extensions.Xunit.Hosting/IGenericHostFixture.cs (1)
  • ConfigureHost (30-30)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (3)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs (4)
  • WebHostTest (8-76)
  • WebHostTest (17-23)
  • WebHostTest (25-31)
  • ConfigureApplication (48-57)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (6)
  • HostTest (16-55)
  • HostTest (23-25)
  • HostTest (65-118)
  • HostTest (76-78)
  • HostTest (90-103)
  • Configure (32-36)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (2)
  • IWebHostTest (26-29)
  • IWebHostTest (39-42)
src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (4)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HttpClientExtensions.cs (1)
  • Task (22-27)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (2)
  • Task (53-57)
  • Task (68-72)
src/Codebelt.Extensions.Xunit/Test.cs (2)
  • Task (148-151)
  • Task (153-156)
test/Codebelt.Extensions.Xunit.Tests/TestTest.cs (1)
  • Task (19-23)
src/Codebelt.Extensions.Xunit.Hosting/Internal/HostTest.cs (2)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HostBuilderApplicationExtensions.cs (1)
  • IHostBuilder (20-24)
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (1)
  • Configure (32-36)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs (1)
src/Codebelt.Extensions.Xunit.Hosting/XunitTestLoggerProvider.cs (1)
  • ILogger (25-30)
test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestTest.cs (4)
test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestTest.cs (2)
  • TestCaseOrderer (15-99)
  • OnDisposeManagedResources (88-91)
src/Codebelt.Extensions.Xunit.Hosting/HostTestFactory.cs (1)
  • HostTestFactory (10-35)
src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs (1)
  • IDisposable (55-58)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestTest.cs (1)
  • ConfigureHost (143-158)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTestFactory.cs (3)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTest.cs (3)
  • MinimalWebHostTest (17-66)
  • MinimalWebHostTest (25-27)
  • MinimalWebHostTest (39-53)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/MinimalWebHostTest.cs (3)
  • MinimalWebHostTest (8-71)
  • MinimalWebHostTest (17-23)
  • MinimalWebHostTest (25-31)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixture.cs (2)
  • MinimalWebHostFixture (14-75)
  • MinimalWebHostFixture (19-21)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (3)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (3)
  • WebHostTest (14-61)
  • WebHostTest (22-24)
  • WebHostTest (33-48)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs (3)
  • WebHostTest (8-76)
  • WebHostTest (17-23)
  • WebHostTest (25-31)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixture.cs (2)
  • WebHostFixture (18-108)
  • WebHostFixture (23-25)
test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostFixtureTest.cs (4)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostFixtureTest.cs (4)
  • Fact (15-23)
  • Fact (25-34)
  • Fact (36-48)
  • Fact (50-63)
test/Codebelt.Extensions.Xunit.Hosting.Tests/GenericHostFixtureTest.cs (3)
  • Fact (18-22)
  • Fact (24-29)
  • Fact (31-42)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/InvalidHostTest.cs (2)
  • InvalidHostTest (5-10)
  • InvalidHostTest (7-9)
test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/MinimalValidHostTest.cs (2)
  • MinimalValidHostTest (7-12)
  • MinimalValidHostTest (9-11)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: 🧪 Test (windows-2022, Debug)
  • GitHub Check: 🧪 Test (ubuntu-22.04, Release)
  • GitHub Check: 🧪 Test (ubuntu-22.04, Debug)
  • GitHub Check: 🧪 Test (windows-2022, Release)
🔇 Additional comments (128)
test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/MinimalValidHostTest.cs (1)

1-13: Well-structured test implementation.

This new test class provides a clean, minimal implementation of MinimalHostTest with appropriate constructor parameter passing. It follows good xUnit testing patterns and will serve well as a test asset.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IMinimalWebHostFixture.cs (1)

11-17: Well-designed interface with proper inheritance

The interface is cleanly designed with appropriate inheritance from IMinimalHostFixture and IPipelineTest, following the Interface Segregation Principle. The ConfigureApplicationCallback property clearly communicates its purpose for configuring the HTTP request pipeline in minimal style tests.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingWebHostFixture.cs (1)

9-17: Good implementation of synchronous host execution

The BlockingWebHostFixture correctly implements synchronous behavior by setting the HostRunnerCallback to use host.Run() instead of an asynchronous pattern. This effectively replaces the removed BlockingAspNetCoreHostFixture class mentioned in the PR objectives and maintains the same functionality for capturing exceptions during execution.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixtureExtensions.cs (1)

18-22: Well-implemented validation with proper reuse

The extension method efficiently reuses validation logic by first calling HasValidState() on the casted IGenericHostFixture, then adding web-specific checks for ConfigureApplicationCallback and Application. This follows the DRY principle and creates a clean validation chain through the inheritance hierarchy.

src/Codebelt.Extensions.Xunit.Hosting/GenericHostFixtureExtensions.cs (1)

17-22: Clear validation logic with readable formatting

The extension method properly checks all required properties for a valid IGenericHostFixture: ConfigureServicesCallback, Host, and ConfigureHostCallback. The formatting with logical AND operators on separate lines enhances readability and makes it easy to understand the validation criteria.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IWebHostFixture.cs (1)

9-10: Interface rename and inheritance update looks good.

The renaming from IAspNetCoreHostFixture to IWebHostFixture and changing the inheritance from IHostFixture to IGenericHostFixture aligns with the PR objectives. This change creates a more consistent naming scheme and better reflects the generalized web hosting capabilities.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostFixtureExtensions.cs (2)

18-22: Well-implemented extension method for state validation.

The HasValidState implementation correctly builds upon the base validation from IMinimalHostFixture while adding the necessary web-specific checks. This follows a clean pattern for extension methods.


13-17: Documentation is thorough and clear.

The XML comments clearly explain what constitutes a valid state by listing all required non-null properties. The cross-references to the interfaces are correctly implemented.

test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/InvalidHostTest.cs (1)

5-5: Updated generic constraint is consistent with interface changes.

The constraint change from IHostFixture to IGenericHostFixture properly aligns with the interface hierarchy updates in this PR.

test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/InvalidHostTest.cs (1)

5-5: Updated generic constraint matches interface changes.

Similar to the AspNetCore variant, this constraint update from IHostFixture to IGenericHostFixture correctly aligns with the interface renaming and hierarchy changes.

src/Codebelt.Extensions.Xunit.Hosting/IHostTest.cs (2)

5-11: Good improvement to the interface definition and documentation

The updated documentation and interface hierarchy provide better clarity about the role of IHostTest. The inheritance from IConfigurationTest, IEnvironmentTest, and ITest follows the interface segregation principle well.


14-16: Documentation properly updated to reference IGenericHostFixture

The property documentation correctly reflects the change from IHostFixture to IGenericHostFixture, maintaining consistency with the broader refactoring efforts in the PR.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HostBuilderApplicationExtensions.cs (1)

1-26:

❓ Verification inconclusive

Well-structured extension method for IHostApplicationBuilder

This new extension method provides a clean way to convert an IHostApplicationBuilder to an IHostBuilder, with proper exception handling and clear documentation. The implementation correctly checks if the builder is a WebApplicationBuilder before accessing its Host property.

However, it might be worth considering a more graceful fallback for non-WebApplicationBuilder implementations of IHostApplicationBuilder rather than throwing an exception.


🏁 Script executed:

#!/bin/bash
# Check if there are other implementations of IHostApplicationBuilder in the codebase
rg "class\s+\w+\s+:\s+(?:\w+,\s+)*IHostApplicationBuilder" --type csharp

Length of output: 74


Potential Alternative Fallback Consideration for IHostApplicationBuilder Conversion

The extension method is well-structured with appropriate exception handling and documentation. It correctly checks for a WebApplicationBuilder before converting to an IHostBuilder. However, the concern about having a more graceful fallback for non-WebApplicationBuilder implementations remains.

Our preliminary repository search using the regular expression did not reveal any additional implementations of IHostApplicationBuilder. Given that the search result was inconclusive, please manually verify whether any other concrete implementations exist (or are likely to be introduced) that might benefit from a fallback strategy rather than triggering an exception.

test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/ValidHostTest.cs (1)

8-10: Class inheritance and constructor properly updated

The class has been correctly updated to use GenericHostFixture instead of HostFixture, aligning with the refactoring changes in the PR. This maintains consistency with the framework changes.

test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/ValidHostTest.cs (1)

6-8: Class inheritance and constructor properly updated for web hosting

The class has been correctly modified to use WebHostTest<WebHostFixture> instead of the previous pattern, aligning with the interface and class renaming mentioned in the PR objectives. This maintains consistency with the broader changes in the package.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/IWebHostTest.cs (1)

6-8: Interface inheritance change appears appropriate.

The change from inheriting IGenericHostTest to IHostTest aligns with the PR objective of interface restructuring. This change harmonizes with the broader refactoring of renaming interfaces and classes throughout the codebase.

src/Codebelt.Extensions.Xunit.Hosting/IGenericHostFixture.cs (1)

11-31: New interface provides clear extension points for host configuration.

The IGenericHostFixture interface appropriately extends IHostFixture to provide Microsoft DI integration capabilities. The callback properties and method signatures are well-documented and follow established patterns for configuration in .NET hosting.

The void ConfigureHost(Test hostTest) method expects a parameter that inherits from HostTest<T> according to the documentation. This is validated in the implementation seen in the relevant code snippets from GenericHostFixture.cs, which includes proper null and type checking.

src/Codebelt.Extensions.Xunit.Hosting/IEnvironmentTest.cs (1)

6-14: Renaming enhances consistency and clarity.

The renaming of the interface from IHostingEnvironmentTest to IEnvironmentTest and its property from HostingEnvironment to Environment improves naming consistency while maintaining the same functionality. This change aligns with modern .NET naming conventions and the PR's objective of interface renaming.

src/Codebelt.Extensions.Xunit.Hosting/IMinimalHostFixture.cs (1)

12-26: New minimal host fixture interface is well-structured.

The IMinimalHostFixture interface provides a streamlined approach for Microsoft DI integration in unit tests using the minimal hosting model. The documentation clearly indicates the purpose and usage of each member, and the interface design follows consistent patterns with other fixtures in the codebase.

This addition aligns with the PR objective of introducing new fixtures, specifically the "minimal style implementation" mentioned in the PR summary. The use of IHostApplicationBuilder reflects modern .NET 6+ approaches to application configuration.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/MinimalWebHostTest.cs (3)

33-45: Ensure fixture initialization is thread-safe if shared across tests.

If multiple tests share the same IMinimalWebHostFixture instance concurrently, reassigning the callbacks in InitializeHostFixture may cause data races or unexpected overrides. Confirm that each test has a unique fixture instance, or ensure thread safety.


58-70: Confirm usage of AddFakeHttpContextAccessor.

This suggests test-specific logic that might not suit production scenarios. Ensure that any test-only service registrations are segregated appropriately and do not leak into production code paths.


17-23:

✅ Verification successful

Validate optional callbacks for null usage.

The constructor gracefully handles null callback parameters by using the ? operator for invocation. However, verify whether passing null might produce unexpected behavior or partial configuration.


🏁 Script executed:

#!/bin/bash
# Grep lines where we rely on _pipelineConfigurator or _serviceConfigurator in this codebase without null checks
rg "_pipelineConfigurator[^?]" -A 2
rg "_serviceConfigurator[^?]" -A 2

Length of output: 11383


Optional Callback Null Handling Validated

After verifying the usage of the optional callback parameters across the codebase, we found that:

  • The constructor safely resolves the callerType using null‐conditional operators.
  • All invocations (e.g., via ?.Invoke(...)) consistently guard against null values.

There are no instances where these callbacks are directly invoked without null checking. However, please ensure that the design choice to allow partial configuration when callbacks are null is intentional and clearly documented.

src/Codebelt.Extensions.Xunit.Hosting/Internal/MinimalHostTest.cs (1)

28-38: Check concurrency behavior when reassigning fixture callbacks.

Similar to the ASP.NET Core fixture, reassigning callbacks in InitializeHostFixture can cause race conditions if multiple tests share the same fixture. Confirm that test fixtures are unique per test or ensure synchronization.

src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTestFactory.cs (1)

21-33: Verify concurrency handling for host test creation.

These static factory methods may be invoked repeatedly for multiple tests. Confirm whether creating shared IMinimalHostFixture instances or reusing them across calls creates side effects.

test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostTestFactoryTest.cs (1)

28-44: LGTM! Thorough host builder context verification

This test effectively verifies that the host builder context properties are properly initialized and that the application name is set correctly to the assembly name. The assertions are comprehensive, checking all key properties.

test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostFixtureTest.cs (6)

9-9: LGTM! Class renamed for consistency with new naming conventions

The class has been correctly renamed from AspNetCoreHostFixtureTest to WebHostFixtureTest to align with the broader refactoring of renaming interfaces and classes in the project.


11-11: LGTM! Constructor updated to match new class name

The constructor has been updated to reflect the class name change.


19-19: LGTM! Fixture instance updated to use new class name

The fixture instance has been updated to use the new WebHostFixture class instead of AspNetCoreHostFixture.


29-30: LGTM! Fixture and test instances updated to use new class names

Both the fixture instance and the invalid host test have been updated to use the new WebHostFixture class.


40-40: LGTM! Fixture instance updated to use new class name

The fixture instance has been updated to use the new WebHostFixture class.


54-54: LGTM! Fixture instance updated to use new class name

The fixture instance has been updated to use the new WebHostFixture class.

src/Codebelt.Extensions.Xunit.Hosting/HostTestFactory.cs (1)

1-36: LGTM! Well-designed factory pattern implementation

This new HostTestFactory class provides a clean and flexible API for creating IHostTest instances with various configuration options. The use of optional parameters allows for simple usage in basic scenarios while supporting more complex configurations when needed.

The XML documentation is thorough and clearly explains the purpose of each method and parameter.

test/Codebelt.Extensions.Xunit.Hosting.Tests/MinimalHostFixtureTest.cs (6)

9-17: LGTM! Test class setup is clean and follows best practices

The test class is well-structured with a private field for the fixture and proper initialization in the constructor. This approach ensures that each test has a fresh instance of the fixture.


18-22: LGTM! Proper null check testing

This test correctly verifies that the ConfigureHost method throws an ArgumentNullException when passed a null argument, which is an important validation for API robustness.


24-29: LGTM! Type compatibility check implemented correctly

This test verifies that the ConfigureHost method throws an ArgumentOutOfRangeException when provided with an incompatible host test type, which is crucial for type safety.


31-42: LGTM! Successful host configuration verification

This test ensures that the ConfigureHost method correctly configures the host when provided with a valid host test, checking that all essential properties are properly initialized.


44-49: LGTM! Resource disposal testing

This test verifies that the Dispose method properly cleans up resources by checking the Disposed property, which is essential for classes implementing IDisposable.


51-56: LGTM! Async resource disposal testing

This test verifies that the DisposeAsync method properly cleans up resources asynchronously, which is essential for classes implementing IAsyncDisposable.

src/Codebelt.Extensions.Xunit.Hosting/GenericHostFixture.cs (5)

8-15: Implementation follows good naming practices and inheritance hierarchy.

The class is properly defined with clear naming and inheritance from HostFixture, implementing the IGenericHostFixture interface. The class design and documentation are well-structured.


24-38: Parameter validation is thorough and well-documented.

The method properly validates the hostTest parameter with appropriate exceptions for null values and incorrect types. The documentation clearly specifies these validation rules.


40-64: Host configuration follows best practices.

The HostBuilder configuration is comprehensive, including content root, environment, application configuration with appropriate JSON files, environment variables, and host configuration. The approach aligns with standard practices for setting up test hosts.


66-72: Good use of conditional compilation for NET9_0_OR_GREATER.

The service provider validation is conditionally compiled for NET9_0_OR_GREATER, ensuring compatibility across different .NET versions while enabling enhanced validation in newer versions.


81-91: Property declarations are clear and well-documented.

The delegate properties for host and service configuration are properly defined with clear documentation explaining their purpose.

src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixture.cs (4)

6-12: Clear documentation explaining the relationship to GenericHostFixture.

The remarks clearly indicate this is the "modern" minimal style implementation of GenericHostFixture, which helps users understand the design philosophy and when to use each implementation.


32-36: Appropriate parameter validation.

Similar to the GenericHostFixture, this class properly validates the hostTest parameter with appropriate exceptions for null values and incorrect types.


37-41: Modern host configuration using HostApplicationBuilder.

The implementation appropriately uses the newer Host.CreateApplicationBuilder() pattern with HostApplicationBuilderSettings, which aligns with modern .NET hosting practices for minimal APIs.


55-59: Delegate property for modern host configuration.

The delegate property type correctly uses IHostApplicationBuilder instead of IHostBuilder, aligning with the modern minimal API approach.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostFixture.cs (4)

13-18: Class renamed from AspNetCoreHostFixture to WebHostFixture.

The renaming from ASP.NET Core-specific naming to more general Web naming is consistent with the PR objectives and aligns better with broader hosting models. The class now inherits from GenericHostFixture instead of directly from HostFixture.


30-41: Updated parameter validation for WebHostTest.

The parameter validation in ConfigureHost has been updated to check for WebHostTest<> instead of AspNetCoreHostTest<>, maintaining consistency with the class renaming throughout the codebase.


69-71: Variable renamed from HostingEnvironment to Environment.

The variable has been renamed for consistency with the base class. This change aligns with the property naming in the HostFixture base class.


94-94: Method call changed to HostRunnerCallback.

The direct call to a method has been replaced with a delegate callback pattern, which provides more flexibility and better separation of concerns.

test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MvcWebHostTestTest.cs (3)

13-13: Class renamed to align with the new fixture naming.

The test class has been updated from MvcAspNetCoreHostTestTest to MvcWebHostTestTest to maintain consistency with the renamed fixture classes.


15-18: Updated field and constructor parameter types.

The field and constructor parameter types have been updated from AspNetCoreHostFixture to WebHostFixture to align with the renamed fixture classes.


20-20: Updated service resolution path.

The service resolution has been updated to use hostFixture.Host.Services instead of hostFixture.ServiceProvider, reflecting the structural changes in the fixture classes. This provides a more consistent service resolution pattern.

test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestFactoryTest.cs (4)

7-7: Class renamed from GenericHostTestFactoryTest to HostTestFactoryTest

The class has been appropriately renamed to align with the PR objectives of renaming interfaces and classes. This change is consistent with the broader refactoring effort to update the hosting infrastructure.


9-9: Constructor name updated to match class name

The constructor has been correctly updated to reflect the class name change, maintaining consistency.


18-24: Updated method call from GenericHostTestFactory to HostTestFactory

The code has been properly refactored to use the new HostTestFactory.Create method instead of GenericHostTestFactory.Create. This change is consistent with the broader refactoring effort.


34-49: Updated method call to HostTestFactory.CreateWithHostBuilderContext

The code has been correctly refactored to use the new HostTestFactory.CreateWithHostBuilderContext method. This maintains consistency with the new naming conventions in the hosting framework.

test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestFactoryTest.cs (6)

18-22: Well-structured class definition for MinimalWebHostTestFactoryTest

This new test class correctly extends the Test base class and implements a constructor with output helper injection, following the established pattern in the codebase.


24-40: Effective test for security exception handling

This test properly verifies that a security exception is thrown when expected. The test is particularly valuable as it validates error handling when authorization policies are misconfigured.


42-58: Good test for caller type validation

This test appropriately verifies that the caller type's declaring type matches the test class type and that the application name correctly equals the assembly name. The use of host.ToHostBuilder() demonstrates compatibility with the Host Builder pattern.


60-72: Async validation of application name

This test correctly validates that the application name equals the assembly name in an asynchronous context using the RunAsync method. The test is well-structured and follows async best practices.


74-102: Comprehensive test for host builder context validation

This test thoroughly validates that all expected properties in the host builder context are properly initialized and that the application name is set correctly. The nested assertions provide comprehensive verification of the context's state.


104-135: Thorough test for server timing middleware integration

This test effectively validates the integration with the server timing middleware, ensuring that timing information is correctly included in the response headers. The test demonstrates good use of middleware composition and asynchronous patterns.

test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalMvcWebHostTestTest.cs (4)

14-24: Well-structured class definition with proper initialization

The class correctly inherits from MinimalWebHostTest<MinimalWebHostFixture> and initializes the necessary components in the constructor. The test output helper is properly injected into the service provider, ensuring logging works correctly.


26-33: Effective test for HTTP GET request

This test properly validates that a GET request to the "/Fake" endpoint returns a successful response with the expected content. The test follows best practices for asynchronous testing.


44-51: Proper host configuration

The override of ConfigureHost correctly configures the host with the necessary services, including controllers and Xunit test logging. The method adds the appropriate application part to ensure the FakeController is discovered.


53-57: Correct application pipeline configuration

The override of ConfigureApplication properly sets up the application pipeline with routing and endpoint mapping for controllers, which is essential for the HTTP requests in the tests to work correctly.

test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestTest.cs (7)

8-8: Added import for Microsoft.Extensions.Hosting

This import is necessary for accessing the IHostApplicationLifetime which is used to track the host's running state.


16-16: Updated base class to use GenericHostFixture

The class now correctly inherits from HostTest<GenericHostFixture> rather than HostTest<HostFixture>, aligning with the PR's renaming objectives.


18-18: Added field to track host running state

The private boolean field _isHostRunning is added to track the application's running state, which is used in a new test method.


23-29: Updated constructor and service scope initialization

The constructor parameter has been properly updated to accept a GenericHostFixture. The service scope creation now uses hostFixture.Host.Services.CreateScope() instead of hostFixture.ServiceProvider.CreateScope(), and the code registers a callback to track when the application starts.


58-62: Added test to verify host is running

This new test method ensures that the host is correctly started by checking the _isHostRunning flag, which is set in the application started callback.


73-73: Updated environment name reference

The code now correctly uses Environment.EnvironmentName instead of HostingEnvironment.EnvironmentName, aligning with the updated property names.


79-81: Updated factory method and interface verification

The test now correctly uses HostTestFactory.Create() instead of GenericHostTestFactory.Create() and verifies assignment to IHostTest instead of a previous interface, maintaining consistency with the renamed interfaces.

test/Codebelt.Extensions.Xunit.Hosting.Tests/GenericHostFixtureTest.cs (3)

9-9: Good rename to clarify test responsibility.
Renaming the class to GenericHostFixtureTest reflects its focus on the newly introduced GenericHostFixture, enhancing clarity for future maintainers.


11-15: Constructor correctly instantiates the generic fixture.
Instantiating a dedicated GenericHostFixture in the constructor ensures that each test has its own clean fixture instance, preventing unintended cross-test interference.


39-41: Environment and services assertions are correct.
Verifying _hostFixture.Host.Services and _hostFixture.Environment ensures that the host is properly configured and all services are accessible.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/Internal/WebHostTest.cs (6)

17-23: Initialization pattern aligns with new callback model.
Passing callbacks and then calling InitializeHostFixture once is a clean approach, preventing partial initialization. This ensures a consistent host configuration.


25-31: Second constructor gracefully handles context-based configurators.
Allowing both parameter sets (with and without HostBuilderContext) improves flexibility. The code correctly defers to the same initialization routine.


33-46: Initialization logic ensures valid state before finalization.
By checking hostFixture.HasValidState() and wiring up the callbacks only if necessary, you avoid repeated configuration. This is a well-structured approach.


48-57: Configuring the application pipeline dynamically.
Deferring the pipeline setup to _pipelineConfigurator or _pipelineConfiguratorWithContext allows flexible middleware insertion. This design is test-friendly and extensible.


59-63: Host builder context creation is straightforward.
Building and storing a HostBuilderContext inside ConfigureHost is a clean pattern; it prevents accidental reuse of a stale context.


65-75: Encouraging test flexibility with service configurators.
The optional _serviceConfigurator and _serviceConfiguratorWithContext facilitate customizing registrations per test scenario, which is good practice.

test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestTest.cs (6)

17-17: Renamed test class aligns with new hosting model.
Renaming to WebHostTestTest clarifies that it tests the new WebHostTest<T> implementation.


22-25: Constructor usage of hostFixture.Host.Services.
Pulling services from hostFixture.Host.Services is consistent with the fixture's new structure, ensuring all dependencies are properly configured.


38-38: Consistent logger retrieval.
Retrieving ILogger<WebHostTestTest> from the pipeline's ApplicationServices is correct; it aligns with the new fixture approach to application-level service resolution.


118-125: Logging message refined and validated in test.
“Hello stranger” logging replaces the previous message, and the assertion properly verifies the log entry. This preserves a robust test of the logging pipeline.


131-136: Ensuring new interfaces are covered correctly.
Expanding the interface checks to IHostTest and IEnvironmentTest affirms that the new hosting abstractions remain validated by the test.


144-144: Supports more explicit logs during ConfigureApplication.
Explicitly logging from ConfigureApplication helps diagnose pipeline setup. This is beneficial for debugging complex middleware arrangements.

src/Codebelt.Extensions.Xunit.Hosting/MinimalHostTest.cs (1)

66-69: Verify logic around skipping fixture initialization.
When skipHostFixtureInitialization is true, the constructor immediately returns, bypassing HasValidState() checks, host assignment, and final configuration steps. Confirm that callers setting this flag can safely handle Host and environment configuration themselves. Otherwise, partial or uninitialized state may cause test failures down the line.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTest.cs (1)

41-43: Validate the outcome of skipping host fixture initialization.
When skipHostFixtureInitialization is true, Host and Application remain unset. Confirm that calling tests can handle this during test runs (e.g., using a different fixture or manual host setup). Otherwise, this may lead to NullReferenceExceptions.

src/Codebelt.Extensions.Xunit.Hosting/IHostFixture.cs (3)

8-14: Good documentation clean-up
These doc comments effectively clarify the interface's scope for app and lifetime management. No issues found.


17-20: Property definition looks appropriate
Exposing IHost as a read-only property ensures immutability and matches the new fixture approach.


23-25: ConfigureCallback documentation alignment
The updated documentation consistently describes the delegate usage for environment and configuration.

src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (4)

10-13: Making the class abstract fosters extensibility
Converting HostFixture to an abstract class clarifies its role as a base for specialized fixtures.


25-27: Constructor visibility
A protected constructor ensures only derived classes can instantiate this abstract fixture, which is consistent.


52-63: HostRunnerCallback property
The property ensures the delegate is never null, which is good. The approach is flexible but be mindful of concurrency if changing the callback after the fixture is in use.


88-88: Renamed environment property
Using Environment aligns with the interface naming conventions and enhances consistency.

src/Codebelt.Extensions.Xunit.Hosting/Internal/HostTest.cs (4)

5-7: Refined internal sealed class
Renaming to HostTest with IGenericHostFixture clarifies the bridging between test logic and the generic host fixture.


14-21: Constructor overloads
Providing constructor overloads for both Action<IServiceCollection> and Action<HostBuilderContext, IServiceCollection> fosters flexibility in test configuration.


28-38: InitializeHostFixture logic
Dynamically sets up the fixture callbacks only if the fixture is not already in a valid state. This approach aligns well with lazy initialization practices.


53-53: HostingEnvironment assignment
Assigning hbc.HostingEnvironment = Environment ensures the environment context remains consistent when configuring the host.

src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (1)

102-102:

✅ Verification successful

Ensure consistency of property initialization and usage.

Host = hostFixture.Host; is assigned here. Verify that this assignment is necessary in all scenarios and that using the fixture's Host property is always valid, especially if initialization was partially skipped.

You can run a quick search to confirm the usage of this property across derived classes and ensure no uninitialized references exist:


🏁 Script executed:

#!/bin/bash
rg -A 5 $'Host\s*='

Length of output: 6851


Final Verification: Consistency of 'Host' Property Usage Confirmed

After reviewing the usage across the codebase, the assignment

Host = hostFixture.Host;

in src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs is used consistently in all derived test classes. The search results confirm that all fixtures—whether for generic hosts, minimal hosts, or ASP.NET Core hosts—assign the Host property in the same way, and it is immediately followed by the configuration call. There is no evidence suggesting that partial initialization leads to uninitialized references.

Action Items:

  • Verify that any scenario involving partial initialization is handled elsewhere (e.g., via appropriate guards or callbacks), ensuring that hostFixture.Host is reliably initialized.
  • No further changes are required to the property assignment; the pattern is consistent and valid across the tests.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/MinimalWebHostTestFactory.cs (1)

44-57:

❓ Verification inconclusive

Handle potential client disposal or re-creation edge cases.

RunAsync(...) disposes of the client via using var client = .... If the same fixture is reused multiple times in parallel, verify that concurrent calls don’t cause conflicts with the test server or misused HttpClient.

To verify concurrency usage across your test code:


🏁 Script executed:

#!/bin/bash
rg -A 4 'MinimalWebHostTestFactory.RunAsync'

Length of output: 1462


Concurrency Check: Fixture and HttpClient Disposal
The current implementation disposes the HttpClient at the end of each RunAsync() call using a using statement. Our search in the tests indicates that RunAsync() is invoked in a straightforward (seemingly sequential) fashion. If the same host fixture is intended to be reused in parallel, please verify that disposing the client won’t lead to conflicts with the test server or unexpected side effects when tests run concurrently. Consider confirming that:

  • The host fixture isn’t shared across parallel tests—or if it is, that its lifecycle correctly isolates each test’s client instance.
  • Concurrent calls (if supported) do not lead to race conditions or resource conflicts with the test server.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (3)

8-14: Documentation for class summary is well-structured.
No issues found. The commentary clearly communicates the class purpose and usage.


16-24: Constructor overload documented clearly.
The supplementary details for parameters are helpful. No concerns about missing logic or validations here.


26-48:

❓ Verification inconclusive

Verify constructor parameter skipHostFixtureInitialization usage.
While this constructor correctly handles skipping host fixture initialization, consider adding or reviewing any existing unit tests to ensure this behavior is tested.

Run the following script to search for tests or calls providing skipHostFixtureInitialization = true:


🏁 Script executed:

#!/bin/bash
rg -A 5 $'WebHostTest\\s*\\(true' test

Length of output: 37


Action Required: Verify Unit Test Coverage for Skipping Host Fixture Initialization

The current constructor implementation in src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (lines 26–48) correctly handles the case when skipHostFixtureInitialization is true. However, our search for tests instantiating WebHostTest with a true value for this parameter did not yield any results. Please verify that there are appropriate unit tests (or add them if missing) to ensure that skipping host fixture initialization is covered.

  • File: src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (lines 26–48)
  • Recommendation: Manually verify if any tests exist that instantiate the class with skipHostFixtureInitialization set to true. If such tests are absent, please add tests that validate:
    • The early return when skipHostFixtureInitialization is true.
    • That no host configuration logic is executed in this scenario.
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs (3)

50-50: Substitution of the old blocking fixture with BlockingWebHostFixture.
This aligns with the new naming conventions and fixture class. Confirm that no references to the old BlockingAspNetCoreHostFixture remain.


76-76: Logger store retrieval update.
Using startup.Host.Services for retrieving the logger appears more direct and consistent with other code in the solution.


110-110: Trivial structural change.
The rest of the method body is unchanged. No additional feedback needed.

test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MinimalWebHostTestTest.cs (8)

18-28: Class construction and initialization are clear.
The dependency injection setup for _provider and _pipeline ensures easy reference in tests. This is straightforward and maintainable.


30-52: Test for middleware result is robust.
Verifies both initial body content and final boolean options. No logical or correctness issues noted.


54-64: Conditional test targeting .NET 9.0 or greater.
Using #if NET9_0_OR_GREATER is appropriate. However, if you need coverage on earlier frameworks, consider providing an alternative path or verifying acceptance of skipping this test in lower versions.


66-115: Thorough correlation token tests.
Scopes and request services are well-tested to confirm expected lifetimes. Implementation is clear and correct.


116-128: Logging test is straightforward.
Ensures that log messages can be properly captured and verified via the test store.


129-141: Interface conformance checks.
Validates host test object implements the correct abstractions, which is useful for regression testing.


143-159: Host configuration is well-defined.
The registration of correlation token services and BoolOptions is consistent. No issues found.


160-164: Application configuration pipeline.
Uses BoolMiddleware after logging. The pipeline approach is concise and clear.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (6)

4-4: Good addition of the internal namespace import

This import is necessary for accessing the WebHostTest class in the internal namespace, which is used in the implementation of the factory methods.


24-24: Well-documented parameter addition

The documentation for the new hostFixture parameter clearly explains its purpose and default behavior, maintaining the quality of the API documentation.

Also applies to: 37-37, 51-51, 66-66


26-26: Good API extension approach

Adding an optional parameter maintains backward compatibility while providing more flexibility to consumers. This aligns well with the PR objective of renaming interfaces and enhancing customization options.

Also applies to: 39-39, 53-53, 68-68


28-28: Well-implemented null coalescing pattern

The implementation correctly uses the provided hostFixture or falls back to creating a new WebHostFixture when none is provided, ensuring backward compatibility.

Also applies to: 41-41


39-39: Method rename aligns with interface changes

Renaming from what was likely CreateWithContextAsync to CreateWithHostBuilderContext maintains consistency with the broader interface renaming changes in this PR.


24-68:

✅ Verification successful

Verify usage patterns with the new parameter

The changes look good, but it would be beneficial to ensure that existing test code using these factory methods continues to work as expected with the interface and implementation changes.


🏁 Script executed:

#!/bin/bash
# Find and analyze test files that might be using WebHostTestFactory
echo "Searching for tests using WebHostTestFactory..."
rg "WebHostTestFactory" --type csharp -l | grep -i "test"

# Check if any tests are explicitly using the old IAspNetCoreHostFixture type
echo -e "\nChecking for any references to the old interface name..."
rg "IAspNetCoreHostFixture" --type csharp

Length of output: 4203


All Usage Verified: New Parameter Integration is Sound

The updated methods that now accept an IWebHostFixture are working as expected. Our search confirmed that the test suite (including files such as WebHostTestFactoryTest.cs and MinimalWebHostTestFactoryTest.cs) exercises these methods correctly. The only remaining reference to the old IAspNetCoreHostFixture appears in GlobalSuppressions.cs as part of legacy suppression rules—this seems intentional to avoid a major version bump and does not affect runtime behavior.

Directory.Packages.props (1)

14-14: Dependency version update looks good.

The version update for System.Threading.Tasks.Extensions from 4.6.2 to 4.6.3 is a minor version increment that likely includes bug fixes and small improvements. This aligns with the broader updates in the PR.

src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HttpClientExtensions.cs (1)

21-21: Documentation updated correctly to reflect interface renaming.

The XML documentation has been properly updated to reference IWebHostFixture instead of the previous IAspNetCoreHostFixture, maintaining consistency with the interface renaming strategy described in the PR objectives.

src/Codebelt.Extensions.Xunit.Hosting/MinimalHostFixtureExtensions.cs (1)

1-24: Well-structured extension method for validating host fixture state.

The implementation of HasValidState follows good extension method practices and provides a useful validation mechanism for IMinimalHostFixture instances.

Comment on lines +8 to +14
internal sealed class MinimalWebHostTest : MinimalWebHostTest<IMinimalWebHostFixture>
{
private readonly Action<IApplicationBuilder> _pipelineConfigurator;
private readonly Action<IServiceCollection> _serviceConfigurator;
private readonly Action<HostBuilderContext, IApplicationBuilder> _pipelineConfiguratorWithContext;
private readonly Action<HostBuilderContext, IServiceCollection> _serviceConfiguratorWithContext;
private readonly Action<IHostApplicationBuilder> _hostConfigurator;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Clarify naming to avoid confusion.

Having both this class and its generic base class named MinimalWebHostTest can be confusing. Consider renaming one for clarity, for example:
• Keep the generic base class as MinimalWebHostTest<TFixture>
• Rename this sealed class to ConcreteMinimalWebHostTest or MinimalWebHostTestImpl.

Comment on lines +7 to +13
internal sealed class MinimalHostTest : MinimalHostTest<IMinimalHostFixture>
{
private readonly Action<IServiceCollection> _serviceConfigurator;
private readonly Action<HostBuilderContext, IServiceCollection> _serviceConfiguratorWithContext;
private readonly Action<IHostApplicationBuilder> _hostConfigurator;
private HostBuilderContext _hostBuilderContext;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider renaming for clarity.

Much like its ASP.NET Core counterpart, this class and its generic base class share the same identifier, potentially causing confusion. Evaluate a distinct class name (for instance, ConcreteMinimalHostTest) to promote readability.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 7, 2025

@gimlichael gimlichael merged commit 5c2b1de into main Apr 7, 2025
1 check passed
@gimlichael gimlichael deleted the v10.0.0/support-for-hostapplicationbuilder branch April 7, 2025 19:11
@coderabbitai coderabbitai bot mentioned this pull request Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants